﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Os.Domain;

namespace Os.WebUI.Helpers
{
    public static class ClienteHelper
    {
        public static string LoadCliente(this HtmlHelper helper, IEnumerable clientes, Cliente clienteSelecionado, bool valorDefault)
        {
            string text = string.Empty;
            text += "<select id='Cliente' name='Cliente'>";
            if (valorDefault)
            {
                text += "<option>Todos</option>";
            }
            IEnumerator enumerator = clientes.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Cliente cliente = (Cliente)enumerator.Current;
                    object obj = text;
                    text = string.Concat(new object[]
					{
						obj, 
						"<option value='", 
						cliente.IdCliente, 
						"'"
					});
                    if (cliente.IdCliente == clienteSelecionado.IdCliente)
                    {
                        text += "selected='selected'";
                    }
                    text += ">";
                    text += cliente.Nome;
                    text += "</option>";
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            text += "</select>";
            return text;
        }
    }
}